<?php

class GuessController extends BaseController
{
    public function init()
    {
        parent::init();
        $this->req = $this->getRequest();
    }

    public function indexAction()
    {
        $req = array();
        $req['uid'] = $this->user_id;
        $rest = new \Base\Rest();
        $res = $rest->get('PlayShow','', $req);
        if ($res->isSuccess()) {
            $playList = $res->getResponse();
        }else{
            $playList = array();
        }
        $this->view->playList = $playList;
        $this->view->title = '竞猜列表';
    }

    public function putAction(){
        $parem = $this->req->getPost();
        $targetItem = array();
        if(isset($parem['play_type_a']) && $parem['play_type_a'])
            $targetItem[] = $parem['play_type_a'];
        if(isset($parem['play_type_b']) && $parem['play_type_b'])
            $targetItem[] = $parem['play_type_b'];
        if(isset($parem['play_type_c']) && $parem['play_type_c'])
            $targetItem[] = $parem['play_type_c'];

        if(!isset($parem['show_id']) || !(int)$parem['show_id']){
            Response::Error(201, '请选择竞猜的比赛');
        }
        if(count($targetItem) < 1){
            Response::Error(201, '没有选择任何竞猜结果');
        }

        $req = array('uid' => $this->user_id);
        $postData = array('showing_id'=>$parem['show_id'],'target_id'=>json_encode($targetItem));
        $post = array('payload' => base64_encode(json_encode($postData)));
        $rest = new \Base\Rest();
        $res = $rest->Post('PlayPut', $req, $post);
        $response = (int)$res->getResponse();
        \Util\LogUtil::log('weixi_ziyan_guess',json_encode($response));
        if ($res->isSuccess()) {
            Response::Success($response,'提交成功');
        } else {
            Response::Error(201, $res->getErrorMessage(),$response);
        }
        die();
    }
}